/*
 DNN Content Builder - sourceforge.net/projects/dnncb
 Copyright (c) 2004-2008
 by Emerson Lopes (emersonlopes@gmail.com)

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
 to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions 
 of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 DEALINGS IN THE SOFTWARE.
*/

using System;
using System.Collections;
using System.Data;

namespace DNNContentBuilder 
{
	[Serializable]
	public class ControlTypeInfo 
	{
        
		// Entity member variables for database table epControlType
        
		private Int32 mControlTypeId;
		private string mTitle;
		private string mControlPath;
		private string mTypeName;
		private string mAssemblyName;
		private string mNamespace;
        
		// Calculated Expression member variables for database table epControlType
        
        
		// Entity properties for database table epControlType
        
		public Int32 ControlTypeId 
		{
			get { return mControlTypeId; }
			set { mControlTypeId = value; }
		}
        
        
		public string Title 
		{
			get { return mTitle; }
			set { mTitle = value; }
		}
        
		public string TypeName 
		{
			get { return mTypeName; }
			set { mTypeName = value; }
		}

		public string AssemblyName 
		{
			get { return mAssemblyName; }
			set { mAssemblyName = value; }
		}

		public string NameSpace 
		{
			get { return mNamespace; }
			set { mNamespace = value; }
		}

		public string ControlPath 
		{
			get { return mControlPath; }
			set { mControlPath = value; }
		} 

		/// <summary>
		/// Gets whether this is a linker <see cref="ControlTypeInfo"/>
		/// </summary>
		public bool IsLinker
		{
			get
			{
				return this.Title == "Linker";
			}
		}

		/// <summary>
		/// Gets whether this is a primary key <see cref="ControlTypeInfo"/>
		/// </summary>
		public bool IsPrimaryKey
		{
			get
			{
				return this.Title == "Primary Key";
			}
		}
	}
    
	public class ControlTypeController : BaseController
	{
		public ControlTypeController() : base() {}
		public ControlTypeController(ConnectionProvider cp) : base(cp) {}
        
		public Int32 Add(ControlTypeInfo ControlTypeInfo) 
		{
			return (Int32) base.GetDataProvider().ControlTypeAdd(ControlTypeInfo.Title, ControlTypeInfo.ControlPath, ControlTypeInfo.TypeName, ControlTypeInfo.AssemblyName, ControlTypeInfo.NameSpace);
		}
        
		public void Update(ControlTypeInfo ControlTypeInfo) 
		{
			base.GetDataProvider().ControlTypeUpdate(ControlTypeInfo.ControlTypeId, ControlTypeInfo.Title, ControlTypeInfo.ControlPath, ControlTypeInfo.TypeName, ControlTypeInfo.AssemblyName, ControlTypeInfo.NameSpace);
		}
        
		public void Delete(Int32 controlTypeId) 
		{
			base.GetDataProvider().ControlTypeDelete(controlTypeId);
		}
        
		public ControlTypeInfo GetItem(Int32 controlTypeId) 
		{
			using (IDataReader idr = base.GetDataProvider().ControlTypeGet(controlTypeId))
			{
				ControlTypeInfo infoObject = (ControlTypeInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(ControlTypeInfo));
				return infoObject;
			} 
		}

		public ControlTypeInfo GetItemByPath(string path) 
		{
			using (IDataReader idr = base.GetDataProvider().ControlTypeGetItemByPath(path))
			{
				ControlTypeInfo infoObject = (ControlTypeInfo)DotNetNuke.Common.Utilities.CBO.FillObject(idr, typeof(ControlTypeInfo));
				return infoObject;
			} 
		}

		// Select query methods for database table epControlType
		public ArrayList GetAllControlType() 
		{
			using (IDataReader idr = base.GetDataProvider().ControlTypeGetAllControlType())
			{
				ArrayList infoList = DotNetNuke.Common.Utilities.CBO.FillCollection(idr, typeof(ControlTypeInfo));
				return infoList;
			} 
		}
 	}
}
